﻿<cfsilent>
	<cfscript>
	
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		/*查询教师所在学院的所有专业*/
		sql = "	SELECT
					sbj.sbj_id,sbj.sbj_name
				FROM
					t_subject sbj
					INNER JOIN t_institute i ON i.institute_id = sbj.institute_id
				WHERE
					sbj.institute_id = :depId 
					AND
					sbj.sbj_direction = '0'
				ORDER BY
					sbj.level_code ASC,
					sbj.term_start ASC,
					sbj.sbj_name ASC";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name="depId", value=depId, cfsqltype="cf_sql_varchar");
		
		rs_subject = queryObj.execute(sql=sql).getResult();
		
		/*查询培养方案版本*/
		sql = "	SELECT
					DISTINCT a.grade
				FROM
					t_condition a
					INNER JOIN t_subject sbj ON sbj.sbj_id = a.sbj_id
				WHERE
					sbj.institute_id = :depId 
					AND
					EXISTS(
						SELECT
							0
						FROM
							t_schema b
							INNER JOIN t_subject bsbj ON b.sbj_id = bsbj.sbj_id
						WHERE
							a.grade = b.grade
							AND
							b.grade >= :currentYear - bsbj.schooling_length 
							AND
							bsbj.institute_id = :depId 
					)
				ORDER BY
					a.grade DESC";
		
		queryObj = new Query(datasource = application.dnsSlave);
		
		queryObj.addParam(name="depId", value=depId, cfsqltype="cf_sql_varchar");
		queryObj.addParam(name="currentYear", value=year(now()), cfsqltype="cf_sql_varchar");
		
		rs_edition = queryObj.execute(sql=sql).getResult();
		
		/*查询培养方案修改申请*/
		sql = "	SELECT
					sm.sign_id,
					tch.tch_name,
					sm.grade,sbj.sbj_name,
					sm.sign_reason,
					sm.sign_status,
					sm.date_created,sm.date_valid
				FROM
					t_schema_modify sm
					INNER JOIN t_teacher tch ON tch.tch_id = sm.sign_user_id
					INNER JOIN t_subject sbj ON sm.sbj_id = sbj.sbj_id
				WHERE
					sbj.institute_id = :depId 
				ORDER BY
					sm.date_created DESC";
		
		queryObj = new Query(datasource = application.dnsSlave);
		
		queryObj.addParam(name="depId", value=depId, cfsqltype="cf_sql_varchar");
		
		rs_sign = queryObj.execute(sql=sql).getResult();
		
		
		event.setArg("pageTitle", "教学运行基础数据 - 培养方案");

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");

		targetArgs = structNew();

		if ( rs_edition.recordCount ) {
			currentTab = event.getArg("Edition", rs_edition['grade'][1]);
		}
		else {
			currentTab = "labCreate";
		}
		
		passArgs = structNew();

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('programCourse')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">课程库</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>培养方案
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
                    	<cfloop query="rs_edition">
							<span <cfif currentTab eq rs_edition.grade>class="active"</cfif> id="labSchema<cfoutput>#rs_edition.grade#</cfoutput>" tabTarget="Schema<cfoutput>#rs_edition.grade#</cfoutput>"><cfoutput>#rs_edition.grade#</cfoutput>版</span>
						</cfloop>
						<span <cfif currentTab eq "labCreate">class="active"</cfif> id="labCreate" tabTarget="Create">设置新培养方案</span>
						<cfif rs_sign.recordCount>
							<span <cfif currentTab eq "labHistory">class="active"</cfif> id="labHistory" tabTarget="History">修订历史记录</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
                <cfloop query="rs_edition">
					<div id="Schema<cfoutput>#rs_edition.grade#</cfoutput>" class="tabContent">
                    
                        <cfset sql = "	SELECT
											sbj.institute_id,i.institute_name
										FROM
											t_schema sc
											INNER JOIN t_subject sbj ON sbj.sbj_id = sc.sbj_id
											INNER JOIN t_institute i ON i.institute_id = sbj.institute_id
										WHERE
											i.institute_id = :depId 
											AND
											sc.grade = :grade 
										GROUP BY
											sbj.institute_id,i.institute_name
										ORDER BY
											i.institute_name ASC"/>
                        
                        <cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        
                        <cfset queryObj.addParam(name="depId", value=depId, cfsqltype="cf_sql_varchar")/>
                        <cfset queryObj.addParam(name="grade", value=rs_edition.grade, cfsqltype="cf_sql_char")/>
                        
                        <cfset rs_dep_schema = queryObj.execute(sql=sql).getResult()/>

                        
                        <cfloop query="rs_dep_schema">
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programSchemaEditionDownloadExcel', { Edition=rs_edition.grade })#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载培养方案</span></a>
								</div>	
								<h3><cfoutput>#rs_dep_schema.institute_name#</cfoutput> - [<cfoutput>#rs_edition.grade#</cfoutput>]版培养方案</h3>
								<p><span class="img icon16x16 message"></span>点击专业名称查看该专业[<cfoutput>#rs_edition.grade#</cfoutput>]版培养方案计划课程开设信息</p>
								<hr/>
							</div>

                            <cfset sql = "	SELECT
												sc.sbj_id,sbj.sbj_name,sbj.term_start,sbj.level_code
											FROM
												t_schema sc
												INNER JOIN t_subject sbj ON sbj.sbj_id = sc.sbj_id
											WHERE
												sc.grade = :grade 
												AND
												sbj.institute_id = :depID 
												AND
												sbj.sbj_direction = '0'
											GROUP BY
												sc.sbj_id,sbj.sbj_name,sbj.term_start,sbj.level_code
											ORDER BY
												sbj.sbj_name" />
                            
                            <cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        
							<cfset queryObj.addParam(name="depID", value=rs_dep_schema.institute_id, cfsqltype="cf_sql_varchar")/>
                            <cfset queryObj.addParam(name="grade", value=rs_edition.grade, cfsqltype="cf_sql_char")/>
                            
                            <cfset rs_sbj = queryObj.execute(sql=sql).getResult()/>
							<div class="clearfix">
								<div class="UICardTable">
                                    <cfloop query="rs_sbj">
										<cfset structInsert(targetArgs, "Edition", rs_edition.grade, true) />
										<cfset structInsert(targetArgs, "SubID", rs_sbj.sbj_id, true) />
										<cfset structInsert(targetArgs, "Schema", rs_edition.grade & rs_sbj.sbj_id, true) />
										<dl>
											<dt>
												<a href="<cfoutput>#buildURL('programSchemaEditionBySubject', targetArgs)#</cfoutput>">
													<em class="subject"><!--imgholder--></em>
													<dd>
														<h3><cfoutput>#rs_sbj.sbj_name#</cfoutput></h3>
														<div><cfoutput>#dictAdvice.getTermEnrol(rs_sbj.term_start)#-#dictAdvice.getStudentLevel(rs_sbj.level_code)#</cfoutput></div>
													</dd>
												</a>
											</dt>
										</dl>
									</cfloop>
								</div>
							</div>
							
						</cfloop>
						
					</div>
				</cfloop>
				
				<div id="Create" class="tabContent">
					
					<form id="formCreate" onSubmit="javascript:return processVerfiyForm('formCreate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('schemaCreateDo')#</cfoutput>">
						
						<input name="InstituteID" type="hidden" value="<cfoutput>#depId#</cfoutput>" />
						
						<div class="label">
							<b>执行专业</b>
							<select name="SubjectID" id="SubjectID">
                                <cfloop query="rs_subject">
									<option value="<cfoutput>#rs_subject.sbj_id#</cfoutput>"><cfoutput>#rs_subject.sbj_name#</cfoutput></option>
								</cfloop>
							</select>
						</div>
						
						<div class="label">
							<b>培养方案版本</b>
							<select name="Grade">
								<cfloop from="#(year(now())-4)#" to="#(year(now())+1)#" index="grade">
								<option <cfif grade eq year(now())>selected="selected"</cfif> value="<cfoutput>#grade#</cfoutput>"><cfoutput>#grade#</cfoutput></option>
								</cfloop>
							</select>
						</div>
						
						<hr/>

						<div class="label">
							<b>毕业总学分</b>
							<input name="Credit" id="Credit" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('Credit', 0)#</cfoutput>" />
						</div>
						
						<div class="label">
							<b>学分子项要求</b>
							必修课<input name="CreditRequired" id="CreditRequired" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('CreditRequired', 0)#</cfoutput>" />
							选修课<input name="CreditOptional" id="CreditOptional" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('CreditOptional', 0)#</cfoutput>" />
							素质拓展类<input name="CreditRelish" id="CreditRelish" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('CreditRelish', 0)#</cfoutput>" />
							<p class="notice">此处的各项学分用于毕业资格审核, 如果对于某一个子项不做要求, 请将学分值设置为0</p>
						</div>
						
						<hr/>
						
						<div class="label">
							<b>毕业总学时</b>
							<input name="Period" id="Period" type="text" class="typeSmallInt" verification="integer" maxlength="8" value="<cfoutput>#event.getArg('Period', 0)#</cfoutput>" />
						</div>
						
						<div class="label">
							<b>学时子项要求</b>
							必修课<input name="PeriodRequired" id="PeriodRequired" type="text" class="typeSmallInt" verification="integer" maxlength="8" value="<cfoutput>#event.getArg('PeriodRequired', 0)#</cfoutput>" />
							选修课<input name="PeriodOptional" id="PeriodOptional" type="text" class="typeSmallInt" verification="integer" maxlength="8" value="<cfoutput>#event.getArg('PeriodOptional', 0)#</cfoutput>" />
							<p class="notice">此处的各项学时要求用于毕业资格审核的学时数补充, 如果对于某一个子项不做要求, 请将值设置为0</p>
						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button" type="submit" value="制定培养方案" />
							<input class="button" type="reset" value="重设表格" />
						</div>
						
					</form>
					
				</div>
				
				
				<cfif rs_sign.recordCount>
					
					<div id="History" class="tabContent">
						
						<div class="noticeBlock">
							<h3>培养方案修订申请 历史记录</h3>
							<hr/>
						</div>
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="60">申请人</td>
									<td width="140">对象</td>
									<td>修订原因</td>
									<td width="60">审批进程</td>
									<td width="70">申请时间</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_sign">
									<cfset row ++ />
									<cfset structInsert(passArgs, "REQ", rs_sign.sign_id, true) />
									<tr class="editRows <cfif event.getArg('REQ') eq rs_sign.sign_id> lastEdited</cfif>">
										<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
										<td><cfoutput>#rs_sign.tch_name#</cfoutput></td>
										<td><cfoutput>#rs_sign.sbj_name#</cfoutput> <span class="numeric"><cfoutput>#rs_sign.grade#</cfoutput></span>版</td>
										<td><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_sign.sign_reason )#</cfoutput></td>
										<td><cfoutput>#dictAdvice.getProgressStatus( rs_sign.sign_status )#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateString( rs_sign.date_created, "YYYY/MM/DD" )#</cfoutput></span></td>
										<td><a class="stat info" href="<cfoutput>#buildURL('schemaModifyApply', passArgs)#</cfoutput>"></a></td>
									</tr>							
								</cfloop>
							</tbody>
						</table>
						
					</div>
					
				</cfif>

			</div>
		</li>
	</ul>
</div>
